/**
 * author      : dormi330
 * date        : 2018/7/17
 * description : TODO
 */

package com.deep.trade.infrastructure.mybatis.refund;

import com.deep.trade.application.AppRuntimeEvn;
import com.deep.trade.domain.refund.RefundOrder;
import com.deep.trade.domain.refund.RefundQueryRepository;
import com.deep.trade.domain.refund.RefundType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MybatisRefundQueryRepository implements RefundQueryRepository {

    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private AppRuntimeEvn appRuntimeEvn;

    @Autowired
    private RefundTypeMapper refundTypeMapper;

    @Autowired
    private RefundOrderMapper refundOrderMapper;

    @Override
    public RefundType refundTypeOfId(String refundTypeId) {
        String tenantCode = appRuntimeEvn.getTenantCode();
        return refundTypeMapper.findOneById(tenantCode, refundTypeId);
    }

    @Override
    public List<RefundType> allRefundType() {
        String tenantCode = appRuntimeEvn.getTenantCode();
        return refundTypeMapper.listAll(tenantCode);
    }

    @Override
    public List<RefundType> refundTypeOfItemCatalog(String catalogId) {
        String tenantCode = appRuntimeEvn.getTenantCode();
        return refundTypeMapper.listByCatalog(tenantCode, catalogId);
    }

    @Override
    public RefundOrder refundApplyOfId(String refundApplyId) {
        return refundOrderMapper.findOneById(appRuntimeEvn.getTenantCode(), refundApplyId);
    }

    @Override
    public PageInfo<RefundOrder> listRefundApplyOfMember(String memberId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<RefundOrder> refundOrderList = refundOrderMapper.listByMember(appRuntimeEvn.getTenantCode(), memberId);
        return new PageInfo<>(refundOrderList);
    }

    @Override
    public PageInfo<RefundOrder> listRefundApplyOfSeller(String sellerId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<RefundOrder> refundOrderList = refundOrderMapper.listBySeller(appRuntimeEvn.getTenantCode(), sellerId);
        return new PageInfo<>(refundOrderList);
    }

    @Override
    public PageInfo<RefundOrder> listRefundApplyOfTenant(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<RefundOrder> refundOrderList = refundOrderMapper.listByTenant(appRuntimeEvn.getTenantCode());
        return new PageInfo<>(refundOrderList);
    }

}
